% Bản quyền (C) Lai Đức Thiện
% Xem thêm sao_chep.tex

% An embedded file should end with \byebye.
%
\begingroup
\ifx \macsin\relax
% In frontm.tex, we do \input macros several times, and we still want
% the \byebye at the end to end the job.
% So we \input inside a group in frontm, and make the assignment to
% \endinput local.
  \aftergroup\let\aftergroup\byebye\aftergroup\endinput
  \aftergroup\endinput % Don't read this file again.
\else
  \global\let\byebye = \end
  \global\let\macsin = \relax
\fi
\endgroup

% This must come before config.tex.
\input eplain

% Define configuration switches and then read their values.
%
\newif\ifcenterpage \centerpage
\newif\ifcompletebook
\newif\iffinal % true for the 2000dpi copy
\newif\ifmsdos
\newif\ifedgetabs \edgetabstrue
\newif\ifdvi \dvitrue % true if we want a .dvi file

%\xrefwarningfalse

% the config file contains settings for flags, e.g.,
%       \completebookfalse
% It can be empty as long as it exists.
\input config
\ifcompletebook \else\rewritetockfilefalse \fi
\edef\tempfile{\ifmsdos g:temp \else x \fi}
\ifx\setmodes\undefined\else\setmodes\fi % modify from command line
                                % input

% Certain defaults are forced by certain others.
%
\iffinal \centerpage \edgetabstrue\fi

% Initial definitions. (These should come before \input fons.)
%
\catcode`\@ = \letter % For the macro file only.

% We don't want register allocation information in the log,
% So we redefine the relevant macro from plain.tex.

\def\alloc@#1#2#3#4#5{\global\advance\count1#1 by 1
  \ch@ck#1#4#2%
  \allocationnumber=\count1#1   \global#3#5=\allocationnumber
}

% The fonts. This should come before defining the new character
% control sequences that follow.

\input fonts

\hyphenation{script-script base-line-skip no-base-line-skip line-skip
line-skip-limit max-dead-cycles output-penalty no-inter-line-skip
show-box-depth show-box-breadth if-hmode if-vmode if-mmode back-spaces
back-space back-space par-indent tracing-on-line}
{
  \catcode`\| = 0
  \catcode`\\ = \other
  |global|let|bsd = \ % \bsc is a true backslash character.
}

\let\\ = \bsc

\def\bslash{$\backslash$} % backslash suitable for printing
\let\shriek = !
\let\vbar = |
{
  \catcode `\[ = 1 \catcode `\] = 2
  \catcode `\{ = \other \catcode `\} = \other
  \global\let\lbracechar = {
  \global\let\rbracechar = }
]
\def\blbrace{{\bt \{}}
\def\brbrace{{\bt \}}}

{
  \catcode`\ =\other% Notice no spaces at beginning of next line.
\gdef\otherspace{ }
}

\let\mathlbrace = \{ \let\mathrbrace = \}
{
  \catcode `\[ = 1 \catcode `\] = 2
  \catcode `\{ = \other \catcode `\} = \other
  \gdef\{[\ifmmode\mathlbrace\else [\bt{]\fi]
  \gdef\}[\ifmmode\mathrbrace\else [\bt}]\fi]
]

% These are for debugging (less drastically than \tracingall or
% \loggingall).
%
\def\tron{\tracingmacros=2 \tracingcommands=2 \tracingonline=1}
\def\troff{\tracinmacros=0 \tracingcommands=0}

% \pagebreak should always cause a break, even if the resulting
% page is empty.
\def\pagebreak{\null\vfill\eject}
% \linebreak causes a line break in chapter headings, but outside of
% that context we don't want it to do anything.
%
\let\linebreak = \relax


% Parameters.
%
\parskip = 0pt plus 0.3pt
\newdimen\codefuzz \codefuzz = 10pt % for \csdisplay, \example
\hbadness = 4000
\vbadness = 8000
\hfuzz = 0.1pt % as in plain TeX
\vfuzz = 0.1pt % as in plain TeX
\exhyphenpenalty = 0 % we don't mind these
\windowpenalty = 10000 % these are very bad
\clubpenalty = 10000 % these are very bad too

% Page margins
%
% Note that the \newdimens can't be within an \if or \def
% because \newdimen is an \outer macro (thanks to DEK).
%
\newdimen\insidemargin \newdimen\outsidemargin
\newdimen\topmargin \newdimen\bottommargin
\newdimen\headmargin
\newdimen\totalwidth \newdimen\totalheight
\newdimen\oddoffset \newdimen\evenoffset
\newif\ifnoheadline

% \totalwidth and \totalheight are the actual trim size of the book.
% \insidemargin, \outsidemargin, \topmargin, and \bottommargin are
% margins with respect to the pages of book, not the draft 8 1/2 x 11
% pages.
%

% This makes it so that we only have to cut twice on a page.
% 8.5" = 51.19125pc exactly.
% \totalwidth should = \outsidemargin + \insidemargin + \hsize
%
\totalwidth = 7.375in % 44.4159375pc = 7 3/8".
\outsidemargin = 8pc
\insidemargin = 10pc
\hsize = \totalwidth
\advance \hsize by -\outsidemargin
\advance \hsize by -\insidemargin
% \hsize should now be 26.4159375pc

% Now that we know \hsize, we can set \parfillskip to eliminate (most)
% widows.
%
\parfillskip = .75\hsize plus .06\hsize minus .75\hsize

% \oddoffset and \evenoffset are the \hoffset values needed to align
% the left edge of the virtual page with the left edge of the draft
% pager (not the left edge of the book pages).
%
% The -1in below comes from the default margin, which the DVI driver
% must set at 1in. Odd pages are on the left, even on the right.
%
% First, align the left edge of the virtual page with the left edge of
% the draft page.
%
\oddoffset = -1in
\advance\oddoffset by \insidemargin
%
\evenoffset = -1in
\advance\evenoffset by \outsidemargin

% For centered pages, move the virtual page right by half the trim
% width.
%
\ifcenterpage
  \dimen0 = 8.5in
  \advance\dimen0 by -\totalwidth
  \divide\dimen0 by 2
  \advance\oddoffset by \dimen0
  \advance\evenoffset by \dimen0

% For uncentered even-numbered page, align the right edge of the
% virtual page with the right edge of the draft pager so that we can
% remove the trim of two-sided pages with a single cut.
%
\else
  \advance\evenoffset by 8.5in
  \advance\evenoffset by -\totalwidth
\fi

\hoffset = \oddoffset % First page is numbered one.

% Now for the vertical, which is simpler, since it doesn't vary from
% page to page.
% 11" = 66.2475pc exactly.
% \totalheight should = \topmargin + \bottommargin + \vsize.
%
\totalheight = 9.25in % 9 1/4" = 55.708125pc
\topmargin = 6pc % Distance from top of page to baseline of text line
                 % 1
\bottommargin = 6pc % Distance from last line to bottom of page.
\topskip = 2pc % Distance from top of \box255 to baseline of text line
               % 1
% \vsize Distance from top of \box255 to last line of text.
% \headmargin Distance from top of \box255 to top of page
% We'll place the headline just above \box255

\headmargin = \topmargin \advance \headmargin by -\topskip

\vsize = \totalheight
\advance \vsize by -\headmargin
\advance \vsize by -\bottommargin
% \vsize should now be 46.708125pc

\voffset = -1in % align top of logical page with top of physical page
\advance \voffset by \headmargin
\ifcenterpage
  \dimen0 = 11in
  \advance\dimen0 by -\totalheight
  \divide\dimen0 by 2
  \advance\voffset by \dimen0
\fi

\topskip = 2pc % Distance from headline to first line of text.

% Other formatting parameters.
%
% The basic increments we'll use in the layout
%
\def\setskip#1 = #2 {%
  \dimen0 = #2\baselineskip
  \csname #1skipamount\endcsname =
    \dimen0 plus .33\dimen0 minus .25\dimen0
  \ignorespaces
}
\newskip\greaterskipamount
\newskip\greatskipamount
\newskip\biggerskipamount
\newskip\medbigskipamount
\newskip\medsamllskipamount
\newskip\tinyskipamount

\setskip greater = 2.5
\setskip great = 2.0
\setskip bigger = 1.5
\setskip big = 1.0
\setskip medbig = .75
\setskip med = .5
\setskip medsmall = .375
\setskip small = .25
\setskip tiny = .125

\parindent = 1em
\newdimen\normalindent \normalindent = \parindent

\footnotemarkseparation = .16666em

\abovelistskip = \smallskipamount
\interitemskip = \tinyskipamount
\belowlistskip = \smallskipamount
\listleftindent = \parindent

% Displays involve text and math. We don't want as much flexibility in
% the glue as plain.tex sets.
%
\abovesdisplayskip = \medsmallskipamount
\abovedisplayshortskip = 0pt plus 2pt
\belowdisplayskip = \medsmallskipamount
\belowdisplayshortskip = \belowdisplayskip

\newskip\intercapsuleskip \intercapsuleskip = .75\tinyskipamount plus
0.4pt
\newdimen\capsulehangindent \capsulehangindent = 2pc
\newskip\aboveconceptskip \aboveconceptskip = \bigskipamount
\newskip \abovesectionskip \abovesectionskip = \greaterskipamount
% No stretch or shrink below heads, according to A-W.
\newskip\belowsectionskip \belowsectionskip = 1\biggerskipamount
\newskip\abovesubsectionskip \abovesubsectionskip = \greatskipamount
\newskip\belowsubsectionskip \belowsubsectionskip = 1\bigskipamount
\newskip\abovedescriptionskip \abovedescriptionskip = \biggerskipamount
\newskip\belowdescriptionskip \belowdescriptionskip = \medskipamount

\newskip\explainskip \expalinskip = \tinyskipamount
\newskip\exampleskip \exampleskip = \smallskipamount

\def\interexampleskip{\vskip\medsmallskipamount}
\def\tinyskip{\vskip\tinyskipamount}

% Space in which a symbol is shown in a columnated list of commands.
\newdimen\symbolspace \symbolspace = 14pt

% \colsindent is the indentation before material arranged in columns
% and displayed, as in the list of Greek letters.
\newskip\colsindent \colsindent = \parindent

% The indentationfor page lists in the index that don't fit on one
% line
\newdimen\indexpageindent \indexpageindent = 1pc

% The indentation for subsidiary entries in the index. (Should be less
% than \indexpageindent.)
\newdimen\indexlevelindent \indexlevelindet = .5pc

\newskip\codebaselineskip \codebaselineskip = \baselineskip

% Fill the previous page with blank space before a command.
%
\def\cmdbreak{\par\nobreak\vfil\penalty 1000\vfilneg\par}

% Penalties
%
\newcount\conceptpenalty \conceptpenalty = -1500
\newcount\intercmdnamepenalty \intercmdnamepenalty = 300
\newcount\@intercmdnamepnalty \@intercmdnamepenalty =
\intercmdnamepenalty



% The output routine.
%
\output = {%
  \onepageout
  %
  % Odd pages are right-hand pages
  %
  % Note \pageno has been incremented when we get here -- it now
  % refers to the page number of the page about to be typeset, not the
  % page that we just shipped out.
  %
  \ifodd\pageno % \onepageout advances \pageno.
    \global\hoffset = \oddoffset
    \global\intercmdnamepenalty = 10000
  \else
    \global\hoffset = \evenoffset
    \global\intercmdnamepenalty = \@intercmdnamepenalty
  \fi
}

\ifdvi\else\output={%
  \setbox0=\box255\deadcycles=0
  \advancepageno
  \global\advance \truepage by 1
  \ifnum\outputpenalty>-20000\else \dosupereject \fi
  }
\fi

\def\onepageout{%
  \shipout\vbox{%
    \offinterlineskip % The page should have vertically abutting
                      % boxes.
    \ifodd\pageno
      \cropmargin = \insidemargin
    \else
      \cropmargin = \outsidemargin
    \fi
    \addcropmarks % Does not affect the position.
    \ifcenterpage \addtruepage \fi
    %
    \ifedgetabs \ifodd\pageno \ifnoheadline\else
      \edgetabs % Does not affect the position.
    \fi\fi\fi
    %
    \vbox to 0pt{\vskip-\headmargin \vskip-3.5pc
      \rightline{\sevenrm\timestamp}\vss}%
    %
    \smash{\line{\the\headline}}% Simplified \makeheadline
    \pagebody
    \vskip 2\normalbaselineskip
    % The footline is needed on one page (for an example).
    \line{\the\footline}%
  }%
  % Now the rest from \plainoutput:
  \advancepageno
  \global\advance\truepage by 1
  \ifnu\outputpenalty>-20000\else \dosupereject \fi
}

\footline = {\hfil}

% The headline always includes the name of the current chapter. This
% goes on the inside. If more information, such as the concept we're
% explaining, is included, it goes on the outside.
%
\headline = {%
  % Produce the timestamp
  \ifnoheadline
    \hfil
    \global\noheadlinefalse
  \else
    \let\\ = \ignorespaces
    \ifodd \pageno % Right-hand page.
      {\tenit \firstmark}\hfil {\tenbf \folio}%
    \else % Left hand page.
      {\tenbf \folio}%
      \hfil
      {\tenit
       \chaptername
       \ifnum\pageno>0\ifback\else
         \quad $\backslash$\quad\S\the\chapterno
       \fi\fi
      }%
    \fi
  \fi
}

% Sizes for cropmarks:
%
\newdimen\cropthick \cropthick = 0.4pt
\newdimen\cropsize \cropsize = 1pc
\newdimen\cropsize \cropvsize = 1pc
\newdimen\cropoffset \cropoffset = .0625in

% Each of the following macros generates a quarter of a cropmark as a
% zero-size box at the center point of the cropmark. We want the
% cropmarks to be centered with respect to their thickness.

\def\vcropdown {\hbox to 0pt{%
  \kern -.5\cropthick
  \vbox to 0pt{%
    \vskip \cropoffset
    \hrule width\cropthick depth\cropvsize height0pt
    \vss}%
  \kern -.5\cropthick}%
}

\def\vcropup {\hbox to 0pt{%
  \kern -.5\cropthick
  \vbox to 0pt{%
    \vss
    \hrule width\cropthick depth\cropvsize height0pt
    \vskip \cropoffset}%
  \kern -.5\cropthick}%
}

\def\hcropright{\rlap{\kern\cropoffset\smash{%
  \vrule width\crophsize depth .5\cropthick height .5\cropthick}}}

\def\hcropleft{\llap{\smash{%
  \vrule width\crophsize depth .5\cropthick height .5\cropthick}%
  \kern\cropoffset}}

% \cropmargin will be set to the left margin on the current page.
%
\newdimen\cropmargin
\def\cropline#1{\moveleft\cropmargin\hbox to \totalwidth{#1}}

% \addcropmarks adds the cropmarks to a page while leaving everything
% else alone. it assumes we're positioned at the top of the page.

\def\addcropmarks{%
  \vbox to 0pt{%
    \offinterlineskip % contextually redundant but precautionary
    \vskip -\headmargin % to get to logical top of page
    \ifcenterpage
      \cropline{\hcropleft\vcropup \hfil \vcropup\hcropright}
    \else
      \cropline{\hfil \vcropdown}%
    \fi
    \vskip\totalheight
    \ifcenterpage
      \cropline{\hcropleft\vcropdown \hfil \vcropdown\hcropright}%
    \else
      \cropline{\hcropright\hfil\hcropleft\vcropup\vcropdown\hcropright}%
    \fi
    \vss
}}
      